From 127033f83d309612bc3a386e2519c4d93ff882c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Jard=C3=B3n?= Date: Wed, 23 Sep 2009 16:53:55 +0200 Subject: [PATCH] Bug 596019 - No accessors for GtkDialog buttons Add API for GtkDialog to return widgets by response ID. Added gtk_dialog_get_widget_for_response() to access to all kinds of buttons with all kinds of responses. --- gtk/gtk.symbols | 1 + gtk/gtkdialog.c | 43 +++++++++++++++++++++++++++++++++++++++++++ gtk/gtkdialog.h | 2 ++ 3 files changed, 46 insertions(+) diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 841780b847..81311df9d4 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1126,6 +1126,7 @@ gtk_dialog_add_buttons G_GNUC_NULL_TERMINATED gtk_dialog_get_action_area gtk_dialog_get_content_area gtk_dialog_get_has_separator +gtk_dialog_get_widget_for_response gtk_dialog_get_response_for_widget gtk_dialog_get_type G_GNUC_CONST gtk_dialog_new diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index d463306844..eb25f5224b 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -1120,6 +1120,49 @@ _gtk_dialog_set_ignore_separator (GtkDialog *dialog, priv->ignore_separator = ignore_separator; } +/** + * gtk_dialog_get_widget_for_response: + * @dialog: a #GtkDialog + * @response_id: the response ID used by the @dialog widget + * + * Gets the widget button that uses the given response ID in the action area + * of a dialog. + * + * Returns: the @widget button that uses the given @response_id, or %NULL. + * + * Since: 2.20 + */ +GtkWidget* +gtk_dialog_get_widget_for_response (GtkDialog *dialog, + gint response_id) +{ + GList *children; + GList *tmp_list; + + g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); + + children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); + + tmp_list = children; + while (tmp_list != NULL) + { + GtkWidget *widget = tmp_list->data; + ResponseData *rd = get_response_data (widget, FALSE); + + if (rd && rd->response_id == response_id) + { + g_list_free (children); + return widget; + } + + tmp_list = g_list_next (tmp_list); + } + + g_list_free (children); + + return NULL; +} + /** * gtk_dialog_get_response_for_widget: * @dialog: a #GtkDialog diff --git a/gtk/gtkdialog.h b/gtk/gtkdialog.h index 69d2c0049f..18a18961c8 100644 --- a/gtk/gtkdialog.h +++ b/gtk/gtkdialog.h @@ -148,6 +148,8 @@ void gtk_dialog_set_response_sensitive (GtkDialog *dialog, gboolean setting); void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id); +GtkWidget* gtk_dialog_get_widget_for_response (GtkDialog *dialog, + gint response_id); gint gtk_dialog_get_response_for_widget (GtkDialog *dialog, GtkWidget *widget); -- 2.30.2